//
//  ZJHttpRequestManager.m
//  DataCache
//
//  Created by zhengju on 16/6/30.
//  Copyright © 2016年 zhengju. All rights reserved.
//  下载请保留出处  https://github.com/zhengju/DataCache

#import "ZJHttpRequestManager.h"
#import "AFNetworking.h"
@implementation ZJHttpRequestManager
-(id)initWithUrlString:(NSString *)url andBlock:(httpResquestBlock)block{
    if(self=[super init]){
        [self requestDataWithString:url andBlock:block];
    }
    return self;
}

-(void)requestDataWithString:(NSString *)url andBlock:(httpResquestBlock)tempBlock{
    
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    
    [manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
         
        //解析
        
        self.data=responseObject;
        
        tempBlock(self);
       
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
 
        NSLog(@"%@",error.localizedDescription);
    }];

}

+(instancetype)sharedManager{
    
    static ZJHttpRequestManager *_sharedManager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedManager = [ZJHttpRequestManager alloc];
        
    });
    
    return _sharedManager;
}
@end
